<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>#{bundle.user}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
           <script type="text/javascript">  
                function handleSaveRequestUser(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgUser.hide();  
                    }  
                }
                
                function handleDeleteRequestUser(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgConfirmation.hide();  
                    }  
                }
                
            </script>

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     image="ui-icon-document" rendered="#{menuBean.cekButtonAccess(601,'INS;')}"  
                                     action="#{usersBean.newData()}"  
                                     oncomplete="dlgUser.show()"
                                     process="@this" update=":#{utilityBean.findClientId('displayUser')}"> 
                        <pe:resetEditableValues for="displayUser" />
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgUser.show()"
									rendered="#{menuBean.cekButtonAccess(601,'OPN;')}" 
                                     image="ui-icon-disk" action="#{usersBean.openData()}"
                                     update=":#{utilityBean.findClientId('displayUser')}" > 
                    </p:commandButton>

                    <p:commandButton type="button" value="#{bundle.btnDelete}" image="ui-icon-trash"
                                     onclick="dlgConfirmation.show()"
									  rendered="#{menuBean.cekButtonAccess(601,'DEL;')}" 
                                     update=":#{utilityBean.findClientId('displayUser')}" /> 

                  <!--  <p:commandButton type="push" value="#{bundle.btnPrint}" image="ui-icon-print"/> -->
                </p:toolbarGroup>
            </p:toolbar>
            <br />
            
            <p:dataTable var="user" value="#{usersBean.users}" id="dtUsers"
                         selection="#{usersBean.selectedData}" selectionMode="single" 
                         rowKey="#{user.userId}" sortBy="#{user.userName}" rowIndexVar="noUrut"
                         paginator="true" rows="10" paginatorPosition="bottom" resizableColumns="true"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15,30">
                <p:column style="width: 10px">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                </p:column>
                <p:column style="width: 100px">
                    <f:facet name="header">#{bundle.userName}</f:facet>
                    <h:outputText value="#{user.userName}" />
                </p:column>

                <p:column style="width: 200px">
                    <f:facet name="header">#{bundle.fullName}</f:facet>
                    <h:outputText value="#{user.fullName}" />
                </p:column>

                <p:column style="width: 100px">
                    <f:facet name="header">#{bundle.ugroup}</f:facet>
                    <h:outputText value="#{usersBean.selectItemValueOf(usersBean.avaibleGroup,user.ugroup.ugroupId)}" />
                </p:column>

                <p:column style="width: 100px">
                    <f:facet name="header">#{bundle.branch}</f:facet>
                    <h:outputText value="#{usersBean.selectItemValueOf(usersBean.avaibleBranch,user.branch.branchId)}" />
                </p:column>
                <p:column style="100px">
                    <f:facet name="header">#{bundle.savbank}</f:facet>
                    <h:outputText value="#{branchcfgBean.getBankName(user.savBankId)}" />
                </p:column>
                <p:column style="width: 50px">
                    <f:facet name="header">#{bundle.phone}</f:facet>
                    <h:outputText value="#{user.phone}" />
                </p:column>
                <p:column style="width: 50px">
                    <f:facet name="header">#{bundle.suspended}</f:facet>
                    <h:outputText value="#{user.suspended}" />
                </p:column>
               
            </p:dataTable>        
            
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgConfirmation">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtUsers" 
                                         oncomplete="handleDeleteRequestUser(xhr, status, args)"  
                                         actionListener="#{usersBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlgConfirmation.hide()" type="button" /> 
                    </f:facet>
                </h:panelGrid>
            </p:confirmDialog>
        </h:form>
            <p:dialog header="#{bundle.user}" widgetVar="dlgUser" closable="true" dynamic="true" modal="true" appendToBody="true">
                <p:ajax immediate="true" event="close" listener="#{usersBean.handleClose}"/>
                <h:form>
                <h:panelGrid id="displayUser" columns="2" styleClass="addELIT">
                    <h:outputLabel value= "#{bundle.userName} :" />
                    
                     <p:inputText rendered="#{usersBean.insertedData!=null}" value="#{usersBean.insertedData.userName}" size="40" />

                     <h:outputLabel style="padding: 0 15px 0 0; " value= "#{bundle.fullName} :" />
                    
                    <p:inputText rendered="#{usersBean.insertedData!=null}" value="#{usersBean.insertedData.fullName}" size="25" />
                    
                    <h:outputLabel value= "#{bundle.password} :" />
                    <h:panelGroup>                                               
                        <p:password  rendered="#{usersBean.insertedData!=null}" value="#{usersBean.insertedData.password}" valueChangeListener="#{usersBean.passwordIsChange()}" size="30" feedback="true" inline="true" redisplay="true" />
                    </h:panelGroup>
                        
                    <h:outputLabel value= "#{bundle.ugroup} :" />
                    <h:panelGroup>
                        
                        <p:selectOneMenu value="#{usersBean.insertedData.ugroup.ugroupId}" 
                                         required="true" requiredMessage="#{bundle.group} #{bundle.requiredInput}" style="width: 170px" rendered="#{usersBean.insertedData!=null}">
                            <f:selectItem itemLabel="#{bundle.Select}  #{bundle.ugroup}" itemValue="" />
                            <f:selectItems  value="#{usersBean.avaibleGroup}"/>
                        </p:selectOneMenu>
                    </h:panelGroup>
                    
                    <h:outputLabel value= "#{bundle.branch} :" />
                    <h:panelGroup>
                        
                        <p:selectOneMenu value="#{usersBean.insertedData.branch.branchId}" style="width: 170px" rendered="#{usersBean.insertedData!=null}"
                                         required="true" requiredMessage="#{bundle.branch} #{bundle.requiredInput}" >
                            <f:selectItem itemLabel="#{bundle.Select} #{bundle.branch}" itemValue="" />
                            <f:selectItems value="#{usersBean.avaibleBranch}" />
                        </p:selectOneMenu>
                    </h:panelGroup>
                    <h:outputLabel value= "#{bundle.savbank} :" />
                    <h:panelGroup>
                        
                        <p:selectOneMenu value="#{usersBean.insertedData.savBankId}" label="#{bundle.savbank}" 
                                         requiredMessage="#{bundle.savbank} #{bundle.requiredInput}" required="false" >
                            <f:selectItem itemLabel="#{bundle.Select} #{bundle.savbank}" itemValue="-1" />
                            <f:selectItems value="#{usersBean.avbBank}" />
                             
                        </p:selectOneMenu>
                    </h:panelGroup>
                    <h:outputLabel value= "#{bundle.phone} :" />
                    <h:panelGroup>
                        
                        <p:inputText rendered="#{usersBean.insertedData!=null}" value="#{usersBean.insertedData.phone}" size="25" />
                    </h:panelGroup>
                    
                    <h:outputLabel style="padding:0 15px 0 0;" value= "#{bundle.suspended} :" />
                    <p:selectBooleanCheckbox value="#{usersBean.insertedData.suspended}" />
                </h:panelGrid>

                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnSave}" image="ui-icon-disk" action="#{usersBean.save()}"
                                         update=":#{utilityBean.findClientId('dtUsers')}"       
										  rendered="#{menuBean.cekButtonAccess(601,'UPD;')}" 
                                         oncomplete="handleSaveRequestUser(xhr, status, args)"/>  
                        <p:commandButton immediate="true" value="#{bundle.btnClose}" oncomplete="dlgUser.hide()" image="ui-icon-document"/>
                    </f:facet>
                </h:panelGrid>
                    </h:form>
            </p:dialog>
        
        </ui:composition>
    </h:body>
</html>
